#include<iostream>
#include<string>
#include<set>
#include<algorithm>
#include<iterator>

int main()
{
	using namespace std;
	const int N=6;
	string s1[N]={"buffoon","thinkers","for","heavy","can","for"};
	string s2[N]={"metal","any","food","elegant","deliver","for"};
	
	set<string> A(s1,s1+N);
	set<string> B(s2,s2+N);
	
	ostream_iterator<string,char> out(cout," ");
	set_union(A.begin(),A.end(),B.begin(),B.end(),out);//A，B合并
	set_intersection(A.begin(),A.end(),B.begin(),B.end(),out);//求交集
	set_difference(A.begin(),A.end(),B.begin(),B.end(),out);//求差
	
	set<string> C;
	set_union(A.begin(),A.end(),B.begin(),B.end(),insert_iterator<set<string> > (C,C.begin()));//A，B求并，赋给C
	
	string s3("grungy");
	C.insert(s3);//插入，有序

	copy(C.lower_bound("ghost"),C.upper_bound("spook"),out);
	
	return 0;
}	
